package api

import (
	"gitee.com/jasmine456/devcloud-mini/cmdb/apps/secret"
	restfulspec "github.com/emicklei/go-restful-openapi/v2"
	"github.com/emicklei/go-restful/v3"
	"github.com/infraboard/mcube/http/label"
	"github.com/infraboard/mcube/ioc"
	"github.com/infraboard/mcube/ioc/config/logger"
	"github.com/rs/zerolog"

	"github.com/infraboard/mcenter/apps/domain"
)

func init() {
	ioc.Api().Registry(&handler{})
}

type handler struct {
	service domain.Service
	log     *zerolog.Logger
	ioc.ObjectImpl
}

func (h *handler) Init() error {
	h.log = logger.Sub(secret.AppName)
	//h.service = ioc.GetController(secret.AppName).(secret.Service)
	return nil
}

func (h *handler) Name() string {
	return secret.AppName
}

func (h *handler) Version() string {
	return "v1"
}

func (h *handler) Registry(ws *restful.WebService) {
	tags := []string{"云商凭证管理"}
	ws.Route(ws.GET("/").To(h.ListSecret).
		Doc("云商凭证列表").
		Metadata(restfulspec.KeyOpenAPITags, tags).
		Metadata(label.Auth, label.Enable).
		Metadata(label.Permission, label.Enable).
		Metadata(label.Resource, "云商凭证secrets").
		Metadata(label.Action, "get"))

	ws.Route(ws.POST("/").To(h.CreateSecret).
		Doc("创建云商凭证").
		Metadata(restfulspec.KeyOpenAPITags, tags).
		Metadata(label.Auth, label.Enable).
		Metadata(label.Permission, label.Enable).
		Metadata(label.Resource, "云商凭证secrets").
		Metadata(label.Action, "create"))

	//ws.Route(ws.GET("/{name}").To(h.DescribeDomain).
	//	Doc("查询域").
	//	Param(ws.PathParameter("id", "identifier of the domain").DataType("integer").DefaultValue("1")).
	//	Metadata(restfulspec.KeyOpenAPITags, tags).
	//	Metadata(label.Auth, label.Enable).
	//	Metadata(label.PERMISSION_MODE, label.PERMISSION_MODE_ACL.Value()).
	//	Metadata(label.Allow, user.TypeToString(user.TYPE_SUPPER, user.TYPE_PRIMARY)).
	//	Writes(domain.Domain{}).
	//	Returns(200, "OK", domain.Domain{}).
	//	Returns(404, "Not Found", nil))
	//
	//ws.Route(ws.PUT("/{id}").To(h.PutDomain).
	//	Doc("更新域").
	//	Param(ws.PathParameter("id", "identifier of the domain").DataType("string")).
	//	Metadata(restfulspec.KeyOpenAPITags, tags).
	//	Metadata(label.Auth, label.Enable).
	//	Metadata(label.PERMISSION_MODE, label.PERMISSION_MODE_ACL.Value()).
	//	Metadata(label.Allow, user.TypeToString(user.TYPE_SUPPER, user.TYPE_PRIMARY)).
	//	Reads(domain.CreateDomainRequest{}))
	//
	//ws.Route(ws.PATCH("/{id}").To(h.PatchDomain).
	//	Doc("更新域").
	//	Param(ws.PathParameter("id", "identifier of the domain").DataType("string")).
	//	Metadata(restfulspec.KeyOpenAPITags, tags).
	//	Metadata(label.Auth, label.Enable).
	//	Metadata(label.PERMISSION_MODE, label.PERMISSION_MODE_ACL.Value()).
	//	Metadata(label.Allow, user.TypeToString(user.TYPE_SUPPER, user.TYPE_PRIMARY)).
	//	Reads(domain.CreateDomainRequest{}))
}
